<?php

namespace backend\models;

use Yii;

/**
 * This is the model class for table "edu_question_discuss".
 *
 * @property int $id
 * @property int $question_id 提问问题的问题id号
 * @property int $user_id 评论者的id或者回复者的id
 * @property int $receiver_user_id 被回复者的用户id 默认为空不为空说明是回复别人的
 * @property int $status 状态 0禁用 1启用 1默认
 * @property int $create_time 创建时间
 * @property string $comment 评论的内容
 */
class EduQuestionDiscuss extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'edu_question_discuss';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['question_id', 'user_id', 'create_time', 'comment'], 'required'],
            [['question_id', 'user_id', 'receiver_user_id', 'status', 'create_time'], 'integer'],
            [['comment'], 'string', 'max' => 500],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'question_id' => '问题 ID',
            'user_id' => '用户 ID',
            'receiver_user_id' => '被评论用户 ID',
            'status' => '状态',
            'create_time' => '时间',
            'comment' => '内容',
        ];
    }

    /**
     * 跟用户表edu_user 关联
     * @return \yii\db\ActiveQuery
     */
    public function getUser()
    {
        return $this->hasOne(EduUser::class, ['id' => 'user_id']);
    }

    /**
     * 跟用户表edu_user关联
     * @return \yii\db\ActiveQuery
     */
    public function getUsers()
    {
        return $this->hasOne(EduUser::class, ['id' => 'receiver_user_id']);
    }
}
